<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" language="java"%>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el"%>
<%@ taglib uri="/WEB-INF/pager-taglib.tld" prefix="pg"%>

<html:html xhtml="true">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><bean:message key="formpage.title" /></title>
<html:base />
<link rel="stylesheet" href="css/struts-training.css" charset="UTF-8"	type="text/css" />
</head>

<script>
/**
 * Author   : TUYEN-DM
 * Date     : 2009/05/25 
 * Function : submit action according to the button clicked
 */
function fncSubmitAction(val1,val2,actionName){	
	document.ManageNewsForm.submitAction.value = val1;
	document.ManageNewsForm.action = actionName;

	var strOK = true;

	if (val1 == 'delete'){
		var arrId = document.getElementsByName("idSelections");
		var intCount = 0;
		for(i = 0; i < arrId.length; i ++)	{
			if(arrId[i].checked == true){
				intCount++;				
			}			
		}
		if(intCount == 0){
			alert('<bean:message key="news.deleteidnotselected" />');
			strOK = false;
		}		
	}
	
	if(strOK != false){
		document.ManageNewsForm.submit();	
	}	
}
</script>

<body background="images/blueAndWhiteBackground.gif">
<div align="center">
<h2><bean:message key="searchpage.title" /></h2>

<html:errors /> <html:form action="/submitNewsSearchForm"
	focus="newsTitle" method="GET">

	<table width="60%">
		<tr>
			<td align="right"><bean:message key="news.newstitle" />:</td>
			<td align="left"><html:text property="newsTitle" size="16"
				maxlength="25" /></td>
			<td align="left"><html:image property="searchButton"
				srcKey="image.search" altKey="image.search.alttext"
				bundle="bundle.image" /></td>
		</tr>
	</table>
</html:form></div>

<logic:empty name="NEWS_DETAIL_OBJECTS">
	<div align="center"><bean:message key="prompt.noresults" /> "<c:out
		value='${NewsearchForm.newsTitle}' />"</div>
</logic:empty>

<html:form action="/manageNewsList" method="GET">

	<logic:notEmpty name="NEWS_DETAIL_OBJECTS">
		<pg:pager url="newslist1.do" maxIndexPages="10" maxPageItems="2">
			<div align="center">
			<table class="list">
				<thead class="list">
					<tr class="list">
						<td class="list">&nbsp;</td>
						<td class="list"><bean:message key="news.newstitle" /></td>
						<td class="list"><bean:message key="news.header" /></td>
						<td class="list"><bean:message key="news.body" /></td>
						<td class="list"><bean:message key="news.source" /></td>
						<td class="list"><bean:message key="news.postdatetime" /></td>
					</tr>
				</thead>

				<%
						int i = 1;
						String claz = null;
					%>

				<c:forEach var='news' items='${NEWS_DETAIL_OBJECTS}'>
					<% claz = (i%2 != 0) ? "odd" : "even"; %>
					<pg:item>
						<tr class="<%= claz %>">

							<td><html-el:multibox property="idSelections">
								<c:out value='${news.newsID}' />
							</html-el:multibox></td>

							<td><html-el:link
								page="/showNewsForm.do?action=Edit&amp;newsTitle=${news.newsTitle}">
								<c:out value='${news.newsTitle}' />
							</html-el:link></td>

							<td><bean:write name="news" property="header" filter="false" />
							</td>

							<td><bean:write name="news" property="body" filter="false" />
							</td>
							<td><c:out value='${news.source}' /></td>
							<td><c:out value='${news.postDateTime}' /></td>
						</tr>
					</pg:item>

					<% i++; %>
				</c:forEach>
			</table>

			<TABLE width="80%" border="0">
				<TR>
					<TD>&nbsp;</TD>
				</TR>
				<TR align="center">
					<TD><pg:index>

						<pg:prev>
							<a href="<%= pageUrl%>">[&lt;&lt;Prev]</a>
						</pg:prev>&nbsp;

								<pg:pages>
							<a href="<%= pageUrl %>">&nbsp;<%= pageNumber %>&nbsp;</a>
						</pg:pages>&nbsp;

								<pg:next>
							<a href="<%= pageUrl%>">[Next&gt;&gt;]</a>
						</pg:next>

					</pg:index></TD>
				</TR>
				<TR>
					<TD>&nbsp;</TD>
				</TR>
			</TABLE>

			</div>
		</pg:pager>
	</logic:notEmpty>

	<div align="center">
	<table>
		<tr>
			<td><html:image property="newButton" srcKey="image.new"
				altKey="image.new.alttext" bundle="bundle.image"
				onclick="javascript:fncSubmitAction('new','','manageNewsList.do');" />
			</td>

			<c:if test='${not empty NEWS_DETAIL_OBJECTS}'>
				<td><html:image property="deleteButton" srcKey="image.delete"
					altKey="image.delete.alttext" bundle="bundle.image"
					onclick="javascript:fncSubmitAction('delete','','manageNewsList.do'); return false;" />
				</td>
			</c:if>
		</tr>
	</table>
	</div>
	<input type="hidden" id="submitAction" name="submitAction" value="" />
</html:form>
</body>

</html:html>
